package at.ac.tuwien.dse.health.event.bus;

import at.ac.tuwien.dse.health.event.annotation.Observe;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

/**
 * Filters methods that can be used as <i>event handlers</i> by the {@link at.ac.tuwien.dse.health.event.bus.EventBus}.
 * <p/>
 * A <i>event listener</i> is a method annotated with {@link at.ac.tuwien.dse.health.event.annotation.Observe} that takes exactly one argument.
 *
 * @author Bernhard Nickel
 * @author Gregor Schauer
 * @author Dominik Strasser
 */
public class EventMethodFilter implements ReflectionUtils.MethodFilter {
	static EventMethodFilter instance = new EventMethodFilter();

	public static EventMethodFilter getInstance() {
		return instance;
	}

	@Override
	public boolean matches(Method method) {
		return method.isAnnotationPresent(Observe.class) && method.getParameterTypes().length == 1;
	}
}
